home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / midi / gfft.lha / gfft-2.03 / source / gfft-2.03-source.lha / wbenchm.c < prev    next >
C/C++ Source or Header  |  1996-01-02  |  5KB  |  227 lines

  1. /***************************************************************************
  2.  *          Copyright (C) 1994  Charles P. Peterson                  *
  3.  *         4007 Enchanted Sun, San Antonio, Texas 78244-1254             *
  4.  *              Email: Charles_P_Peterson@fcircus.sat.tx.us                *
  5.  *                                                                         *
  6.  *          This is free software with NO WARRANTY.                  *
  7.  *          See gfft.c, or run program itself, for details.              *
  8.  *              Support is available for a fee.                      *
  9.  ***************************************************************************
  10.  *
  11.  * Program:     gfft--General FFT analysis
  12.  * File:        wbenchm.c
  13.  * Purpose:     workbench GUI main functions
  14.  * Author:      Charles Peterson (CPP)
  15.  * History:     19-Nov-1993 CPP; Created.
  16.  *              19-Jan-1995 CPP; (1.22) Make GFFT shell bigger & go away
  17.  *              20-Jan-1995 CPP; (1.23) Use Icon Tooltypes
  18.  * Comments:    Workbench GUI.  Amiga Dependent!
  19.  */
  20.  
  21. #ifdef AMIGA
  22.  
  23. #include <stdlib.h>    /* exit()     */
  24. #include <stdio.h>     /* sprintf() */
  25. #include <string.h>
  26. /*
  27.  * Amiga includes
  28.  */
  29. #include <exec/types.h>
  30. #include <exec/exec.h>
  31. #include <workbench/workbench.h>
  32. #include <workbench/icon.h>
  33. #include <workbench/startup.h>
  34. #include <intuition/intuition.h>
  35. #include <clib/intuition_protos.h>
  36. #include <clib/exec_protos.h>
  37. #include <proto/icon.h>
  38. #include <proto/dos.h>
  39. #include <dos/dos.h>
  40.  
  41. /*
  42.  * GFFT includes
  43.  */
  44. #include "gfft.h"
  45. #include "settings.h"  /* for testing */
  46. #include "wbench.h"
  47.  
  48. /*
  49.  * Default console (Many thanks to SAS for making this possible.)
  50.  */
  51. char __stdiowin[] = "CON:0/000/640/200/GfftConsole";
  52. char __stdiov37[]= "/AUTO/CLOSE";
  53.  
  54. extern struct WBStartup *WBenchMsg;
  55.  
  56. /*
  57.  * Semi-static variables (used also by wbdialog)
  58.  */
  59. LONG num_files = 0;
  60. LONG file_index = 0;
  61. int Tooltype_Errors = 0;
  62. extern BOOLEAN Tooltype_Errors_Reported;
  63.  
  64.  
  65. /*
  66.  * Statics
  67.  */
  68. static int within_workbench_loop = FALSE;
  69. static void workbench_dialog_loop (void);
  70. static void process_tooltypes (UBYTE *name);
  71.  
  72.  
  73. void workbench_main (void)
  74. {
  75.     LONG olddir;
  76.     open_libraries ();
  77.  
  78. /*
  79.  * Process GFFT.info tooltypes, if any
  80.  */
  81.     if (WBenchMsg && WBenchMsg->sm_NumArgs && WBenchMsg->sm_ArgList)
  82.     {
  83.     struct WBArg *wbarg = WBenchMsg->sm_ArgList;
  84.  
  85.     olddir = CurrentDir (wbarg->wa_Lock);
  86.     process_tooltypes (wbarg->wa_Name);
  87.     CurrentDir (olddir);
  88.     }
  89.     Tooltype_Errors = Error_Count;
  90.  
  91. /*
  92.  * Process project icons/files, if any
  93.  */
  94.  
  95.     if (WBenchMsg && (num_files = WBenchMsg->sm_NumArgs - 1))
  96.     {
  97.     /*
  98.      * Loop through selected project icon(s)
  99.      */
  100.     for (file_index = 0; file_index < num_files; file_index++)
  101.     {
  102.         /*
  103.          * Change to directory containing selected object (file)
  104.          * then, open it
  105.          * then, change back
  106.          * then, run dialog window
  107.          * (if error, try next file)
  108.          */
  109.         LONG i = file_index;
  110.         CATCH_ERROR
  111.         {
  112.         olddir = CurrentDir (WBenchMsg->sm_ArgList[i+1].wa_Lock);
  113.         set_read (WBenchMsg->sm_ArgList[i+1].wa_Name);
  114.         process_tooltypes (WBenchMsg->sm_ArgList[i+1].wa_Name);
  115.         CurrentDir (olddir);
  116.         workbench_dialog_loop ();
  117.         }
  118.         END_CATCH_ERROR;
  119.     }
  120.     }
  121.     else
  122.     {
  123.     /* 
  124.      * No project files selected
  125.      */
  126.     CATCH_ERROR
  127.     {
  128.         workbench_dialog_loop ();
  129.     }
  130.     END_CATCH_ERROR;
  131.     }
  132. }
  133.  
  134.  
  135. /*
  136.  * The following functions permit the CLI interactive mode to be activated
  137.  * from the workbench, and the CLI to be started from the workbench, and
  138.  * to return the the original mode.
  139.  */
  140.  
  141. static void workbench_dialog_loop (void)
  142. {
  143.     int next_action = WORKBENCH_MODE;
  144.     BOOLEAN help_displayed = FALSE;
  145.  
  146.     within_workbench_loop = TRUE;
  147.     Plot = ANY_PLOT;
  148.     while (next_action == WORKBENCH_MODE ||
  149.        next_action == INTERACTIVE_MODE)
  150.     {
  151.     switch (next_action)
  152.     {
  153.     case WORKBENCH_MODE:
  154.         next_action = workbench_dialog ();
  155.         break;
  156.     case INTERACTIVE_MODE:
  157.         if (!help_displayed)
  158.         {
  159.         printf ("This is the GFFT CLI-interactive interface...\n");
  160.         printf ("Enter WORKBENCH to return to dialog window.\n");
  161.      printf ("Enter QUIT to quit without returning to dialog window.\n");
  162.         printf ("Enter HELP to see a complete list of commands.\n");
  163.         help_displayed = TRUE;
  164.         }
  165.         cli_interactive_loop (FALSE);
  166.         next_action = WORKBENCH_MODE;
  167.         break;
  168.     }
  169.     }
  170.     within_workbench_loop = FALSE;
  171. }
  172.           
  173. char *workbench_command (char *arguments)
  174. {
  175.     int previous_command_mode = CommandMode;
  176.  
  177.     if (within_workbench_loop)
  178.     {
  179.     CommandMode = WORKBENCH_MODE;
  180.     return arguments;
  181.     /*
  182.      * return to workbench through cli_interactive_loop
  183.      */
  184.     }
  185.     else
  186.     {
  187.     workbench_dialog_loop ();
  188.     CommandMode = previous_command_mode;
  189.     }
  190.     return arguments;
  191. }
  192.  
  193. static void process_tooltypes (UBYTE *name)
  194. {
  195.     int starting_error_count = Error_Count;
  196.     struct DiskObject *disk_obp;
  197.  
  198.     if (disk_obp = GetDiskObject (name))
  199.     {
  200.     int i;
  201.     char *tool;
  202.     int previous_command_mode = CommandMode;
  203.  
  204.     CommandMode = BATCH_MODE;
  205.  
  206.     for (i = 0; tool = disk_obp->do_ToolTypes[i]; i++)
  207.     {
  208.         if (!ignore_tooltype (tool))
  209.         {
  210.         execute_command_line (tool, NULL);
  211.         }
  212.     }
  213.  
  214.     CommandMode = previous_command_mode;
  215.     }
  216.     if (Error_Count > starting_error_count)
  217.     {
  218.     Tooltype_Errors += Error_Count - starting_error_count;
  219.     Tooltype_Errors_Reported = FALSE;
  220.     }
  221. }
  222.  
  223.  
  224.  
  225. #endif  /* ifdef AMIGA */
  226.  
  227.